<html>
<head>

    <meta charset="UTF-8">
    <title>手动签到</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">

    <link rel="stylesheet" href="__HOME__/css/weui.css">
    <link rel="stylesheet" href="__HOME__/css/jquery-weui.css">
    <link rel="stylesheet" href="__HOME__/css/style.css">
    <!--<link rel="stylesheet" href="http://at.alicdn.com/t/font_689900_q7w1lloaqzg2e29.css">-->
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_587767_8fpp60gz2ok.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_689900_jcdrhysqlt.css">

    <style type="text/css">
        #autoBox
        {
            margin: 0px;
            padding: 0px;
            border: 1px solid #CCCCCC;
            width: 75%;
        }
        #autoBox li
        {
            clear: both;
            background-color: white;
            color: black;
            position: relative;
            top: 0px;
            left: 0px;
            line-height: 25px;
            width:100%;
            text-align: left;
            overflow: hidden;
        }
        #autoBox li:hover
        {
            background-color: gray;
            color: yellow;
            cursor: pointer;
        }

        .mycenter-top{background: #fff;overflow: hidden;line-height: 60px;padding:20px;}
        .mycenter-top img{border-radius: 50%;float: left;}
        .searchBox {
            overflow: hidden;
            padding: 0 10px;
        }
        .searchBox .inpB {
            background: #fff;
            border: 1px solid #ebebeb;
            line-height: 40px;
            border-radius: 5px;
            width: 62%;
            float: left;
            padding-left: 10px;
        }
        .searchBox .inpB input {
            width: 90%;
            outline: none;
            height: 40px;
        }
        .searchBox .sm {
            background: #fff;
            border: 1px solid #ebebeb;
            line-height: 40px;
            border-radius: 5px;
            width: 10%;
            float: left;
            padding-left: 10px;
        }


        .searchBox .weui-btn {
            width: 20%;
            float: right;
            line-height: 42px;
            font-size: 14px;
        }
        .weui-btn {
            background-color: #ee3c4c;
            border-radius: 5px;
        }
        a {
            text-decoration: none;
            -webkit-tap-highlight-color: rgba(0,0,0,0);
        }
        input{
            margin-right: 10px;
        }


        .inp{
            float:right;padding:5px 15px;margin-top: 10px;background: #bbbbbb;color:#fff;
        }
        .inp1{
            float:right;padding:5px 15px;margin-top: 10px;background: #3ca4ee;color:#fff;
        }

        .icon-saoyisao:before {
            content: "\e631";
            font-size: 25px;
        }
        .sys {
            position: absolute;
            top: 1px;
            right: 17px;
            z-index: 10;
        }
        .icon-shuaxin:before {
            content: "\e619";
            font-size: 20px;
        }

        .weui-btn:after {

            border: 0px solid rgba(0,0,0,.2);

        }
    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="__HOME__/js/jquery.min.js"></script>
</head>


<body class="back1"  >

<div class="index-top-fix">
    <a href="{:url('store/checker.index/index')}?shop_id={$shop_id}" class="iconfont icon-left- left"></a>
    <p class="title">手动签到</p>
  <a  href="javascript:location.replace(location.href);" style="color: black">
       <span class="sys"  style="font-size: 17px ;" >
            <!--<i class="icon icon-shuaxin"></i>-->刷新
         </span>
  </a>
</div>
<div class="searchBox"  style="margin-top: 50px">
    <div class="inpB">
        <!--<input type="text"  id="keyword" placeholder="请输入学生姓名或学号"  >-->
        <input type="text" placeholder="请输入学生学号或姓名" id="stuSearch" name="stuSearch"/>


    </div>
    <div class="sm" >
         <span class="" onclick="weixin_qr()" >
            <i class="iconfont icon-saoyisao"></i>
         </span>
    </div>
    <a class="weui-btn" onclick="search1(this)"> 查询 </a>
    <ul id="autoBox">
    </ul>
</div>
<div id="header"  style="width:100%;background: #ffffff;text-align: center;margin-top: 10px;padding: 10px;display: none" >
    <span  id="name"></span>
    <span  id="stu_no"></span>
    <!--<input id="stu_id" type="hidden"  value="">-->
</div>
<div  id="show" style="display: none">


</div>

<div id="fail"  style="display: none;text-align: center">
    无此学生信息，请输入有效信息查询
</div>
<div  id="list">
    {if $res}
{foreach  name="res" item="v" key="k"}
    <div style="height: 100px;line-height: 50px;margin-top: 10px;padding:0 10px;background: #ffffff;" >
        <div style="width: 70%;float:left;">
            <span>{$v.name}</span>
            <span>{$v.stu_no}</span>
        </div>
        <div style="width: 30%;float:left;height: 50px;line-height: 50px;">
            <span>{$v.start}</span>
            <span>{$v.end}</span>
        </div>

        <div>
            <span   id="c_name">课程：{$v.course_name}</span>
            {if  $v.status ==0}
            <input  type="button"  value="迟到"  class="inp1" onclick="sign1('{$v.stu_no}','{$v.period_id}','{$v.course_name}',3)">
            <input  type="button"  value="请假"  class="inp1" onclick="sign1('{$v.stu_no}','{$v.period_id}','{$v.course_name}',2)">
            <input  type="button"  value="签到"  class="inp1" onclick="sign1('{$v.stu_no}','{$v.period_id}','{$v.course_name}',1)">

           {elseif  $v.status ==1 }
            <input  type="button"  value="迟到"  class="inp1">
            <input  type="button"  value="请假"  class="inp1">
            <input  type="button"  value="已签到"  class="inp">
            {elseif  $v.status ==2 }
            <input  type="button"  value="迟到"  class="inp1">
            <input  type="button"  value="已请假"  class="inp">
            <input  type="button"  value="签到"  class="inp1">
            {elseif  $v.status ==3 }
            <input  type="button"  value="已迟到"  class="inp">
            <input  type="button"  value="请假"  class="inp1">
            <input  type="button"  value="签到"  class="inp1">
       {/if}
        </div>

    </div>
{/foreach}
    {else}
    <div  style="text-align: center;color: #b4b4b4;padding-top: 20px" >该时段暂无课程信息</div>
    {/if}
</div>


</body>
<script src="__HOME__/js/jquery.min.js"></script>
<script src="__HOME__/js/jquery-weui.min.js"></script>
<script type="text/javascript">
    $(function(){

        $.ajaxSetup({cache:false}) ; //不缓存
        //以下代码用于显示检索提示框
        $("#autoBox").hide(); //初始化时隐藏补全提示框
        $("#stuSearch").keyup(function(){ //输入框中的keyup事件激活以下查询行为
            $("#autoBox").html(""); //先清空补全提示框原有内容
            if($("#stuSearch").val().length>0) // 如果输入框不为空
            {
                $.ajax({ //后台调用php文件进行查询
                    type:"post",
                    url:"check",
                    dataType:"json",
                    data:{keywords:$("#stuSearch").val()},
                    success:function(res)
                    {
                       var  a=res.data;
                        $("#autoBox").show();// 显示补全提示框
                        for(i=0;i<a.length;i++) //将结果添加到提示框中
                        {
                            $("#autoBox").append("<li>"+a[i]['name']+" 学号："+(a[i]['stu_no'])+"</li>");
                        }
                        $("#autoBox li").on("click",function(){ //为这些新增的li绑定单击事件，单击后将其值赋到输入框中
                            $("#stuSearch").val($(this).text().substr(-15));
                        })
                        //在提示框的最后添加一个li用来关闭
//                        $("#autoBox").append("<li style='text-align:right'>关闭</li>");
                        $("#autoBox li").on("click",function(){ // 添加单击事件，单击后隐藏提示框
                            $("#autoBox").hide();
                        })
                    }
                });
            }
        })
    })

</script>
<script>

    // 查询防伪码
    function search1(that) {
        var keyword = $("#stuSearch").val();
        if (keyword.length == 0) {

            alert("查询内容不能为空");

        } else {
            $('#list').hide();
            $.post("{:url('store/checker.sign/hand_sign')}", {keyword: keyword}, function (res) {

                var str = '',varr = [];
                if (res.code == 1) {
                    $('#fail').hide();
                   for(var i=0;i<res.data.length;i++){
                       console.log(res.data);
                       if (i == 0){
                           $('#name').text("姓名："+res.data[i].name);
                           $('#stu_no').text(res.data[i].stu_no);
                       }

                       var html = '<div style="height: 50px;line-height: 50px;margin-top: 10px;padding:0 10px;background: #ffffff;" >'+
                           '<div style="width:20%;float:left;">'+
                           '<span >'+res.data[i]['start_time']+'~'+'</span>'+
                           '<span>'+res.data[i]['end_time']+'</span>'+
                           '</div>'+
                           '<div  style="width:80%;float:right;">'+
                           '<span>';
                       if (res.data[i]['status'] == 0){
                            html = html + '<input  type="button"  id="wq" value="迟到" class="inp1" onclick="sign('+res.data[i]['period_id']+','+res.data[i]['course_id']+','+3+')">'+
                                            '<input  type="button"  id="wq" value="请假" class="inp1" onclick="sign('+res.data[i]['period_id']+','+res.data[i]['course_id']+','+2+')">'+
                                '<input  type="button" id="yq" value="签到" class="inp1" onclick="sign('+res.data[i]['period_id']+','+res.data[i]['course_id']+','+1+')"  >';
                       }else if (res.data[i]['status'] == 1){
                           html = html + '<input  type="button"  id="wq" value="迟到"class="inp1">'+
                               '<input  type="button"  id="wq" value="请假" class="inp1">'+
                               '<input  type="button" id="yq" value="已签到" class="inp">';
                       }else if (res.data[i]['status'] == 2){
                           html = html + '<input  type="button"  id="wq" value="迟到"class="inp1">'+
                               '<input  type="button"  id="wq" value="已请假" class="inp">'+
                               '<input  type="button" id="yq" value="签到" class="inp1">';
                       }else if (res.data[i]['status'] == 3){
                           html = html +'<input  type="button"  id="wq" value="已迟到"class="inp">' +
                               '<input  type="button"  id="wq" value="请假" class="inp1">'+
                               '<input  type="button" id="yq" value="签到" class="inp1">';
                       }
                       var html = html + '</span>'+
                                           '</div>'+
                                           '</div>';
                       varr.push(html);
                   }
                    str = varr.join("");
                    $("#show").html(str);
                    $('#show').show();
                    $('#header').show();



                }
                else {
                    $('#fail').show();

                    $('#show').hide();
                }
            })
        }

    }


    function sign(period_id,course_id,status) {

            var stu_no=$('#stu_no').text();
        console.log(period_id);
        console.log(course_id);
        console.log(status);
        console.log(stu_no);
        if(period_id != null && course_id != null && status != null && stu_no != null){
            $.post(
                "{:url('/store/checker.sign/sign')}?shop_id={$shop_id}",
                {
                    stu_no:stu_no,
                    period_id:period_id,
                    course_id:course_id,
                    status:status
                },
                function (res) {
                    if(res.code===1){
                        $.toast(res.msg  , function () {
//                                    location.href = "{:url('store/checker.index/index')}";
                                }
                        );
                    } else {

                        $.toast(res.msg
                                    ,function () {
//                                    location.href = "{:url('store/checker.index/index')}";
                                }
                        );
                    }
                }
            );

        }else{
            alert("信息有误");
        }
    }

    function sign1(sno,pid,c_name,status) {

        console.log(sno);
        console.log(pid);
        console.log(c_name);
        console.log(status);
        if(sno != null && pid != null &&  status != null &&  c_name != null){
            $.post(
                "{:url('/store/checker.sign/sign1')}?shop_id={$shop_id}",
                {
                    period_id:pid,
                    stu_no:sno,
                    status:status,
                    c_name:c_name
                },
                function (res) {
                    if(res.code===1){
                        $.toast(res.msg  , function () {
//                                location.href = "{:url('store/checker.index/index')}";
                            }
                        );
                    } else {

                        $.toast(res.msg
                            ,function () {
//                                location.href = "{:url('store/checker.index/index')}";
                            }
                        );
                    }
                }
            );

        }else{
            alert("信息有误");
        }
    }

</script>
<script src="__HOME__/js/jweixin-1.2.0.js"></script>
<script>

    wx.config({
        debug: false,
        appId: '{$jsconfig.appId}',
        timestamp: '{$jsconfig.timestamp}',
        nonceStr: '{$jsconfig.noncestr}',
        signature: '{$jsconfig.signature}',
        jsApiList: [
            'checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'hideMenuItems',
            'showMenuItems',
            'hideAllNonBaseMenuItem',
            'showAllNonBaseMenuItem',
            'translateVoice',
            'startRecord',
            'stopRecord',
            'onRecordEnd',
            'playVoice',
            'pauseVoice',
            'stopVoice',
            'uploadVoice',
            'downloadVoice',
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'getNetworkType',
            'openLocation',
            'getLocation',
            'hideOptionMenu',
            'showOptionMenu',
            'closeWindow',
            'scanQRCode',
            'chooseWXPay',
            'openProductSpecificView',
            'addCard',
            'chooseCard',
            'openCard'
        ]
    });
    wx.isInit = false;

    /**
     *  学生签到
     */
    function weixin_qr() {
        wx.scanQRCode({
            desc: 'scanQRCode desc',
            needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
            success: function (res) {
                var data = JSON.stringify(res);
                if(res.errMsg === 'scanQRCode:ok'){

                    $.post(
                        "{:url('/store/checker.sign/student_sign')}?shop_id={$shop_id}",
                        {
                            data:data
                        },
                        function (res) {
                            if(res.code===1){

                                $('#stuSearch').val(res.data) ;
                               $.toast(res.msg);

//
                            } else {

                                $.toast(res.msg );
                            }
                        }
                    );

                }else{
                    alert("二维码信息有误");
                }

            }
        });
    }

</script>
</html>